package com.loveprogrammer.eternity.skill.support.skills.passive;

import com.loveprogrammer.eternity.common.Tuple;
import com.loveprogrammer.eternity.model.Character;
import com.loveprogrammer.eternity.skill.support.skills.AbstractPassiveAuraSkill;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0.0
 * @description: 元素抵抗光环
 * @author: eric
 * @date: 2022-08-22 18:07
 **/
public class ElementalResistanceAuraSkill extends AbstractPassiveAuraSkill {

    private int increment;

    public ElementalResistanceAuraSkill(int id, int baseInterval, int level, int order, int maxLevel, String name, String desc) {
        super(id, baseInterval, level, order, maxLevel, name, desc);
    }

    @Override
    protected Tuple<String, List<Character>> skillLaunch(Character character,
                                                         List<? extends Character> attack,
                                                         List<? extends Character> defences) {
        Tuple<String, List<Character>> result = new Tuple<>();
        // 进攻方提升各元素抗性
        increment = getHarm(character);
        StringBuilder builder = new StringBuilder();
        builder.append(character.getName()).append("释放了技能【").append(getName()).append(" (").append(getLevel()).append("级)】\n");
        for (Character member : attack) {

            member.setFlameResistance(member.getFlameResistance() + increment);
            member.setIceResistance(member.getIceResistance() + increment);
            member.setThunderResistance(member.getThunderResistance() + increment);
            member.setPoisonResistance(member.getPoisonResistance() + increment);

            builder.append(member.getName()).append("元素抗性提升【").append(increment).append("】点\n");
        }
        result.setKey(builder.toString());
        result.setValue(new ArrayList<>());
        return result;
    }

    @Override
    protected int computeHarm(Character character) {
        return (int) getLevel() * 3;
    }

    @Override
    protected int computeSecondHarm(Character character) {
        return 0;
    }

    @Override
    public boolean checkLevelUp(int characterLevel) {
        // 每4级升一级
        if(characterLevel % 4 == 0){
            return true;
        }
        return false;
    }

    @Override
    public int defaultHarm() {
        return 100;
    }

    @Override
    public void release(Character character,List<? extends Character> attack, List<? extends Character> defences) {
        for (Character member : attack) {
            member.setFlameResistance(member.getFlameResistance() - increment);
            member.setIceResistance(member.getIceResistance() - increment);
            member.setThunderResistance(member.getThunderResistance() - increment);
            member.setPoisonResistance(member.getPoisonResistance() - increment);
        }
    }

}
